package butines.game.steering.behavior;

import java.util.Collection;

import butines.core.math2d.Vector2D;
import butines.game.steering.Vehicle;

public class Steering {

	private Vector2D steeringForce = new Vector2D();

	private PriorityCombinationBehavior prioritization;

	private SeekBehavior seek;
	private ArrivalBehavior arrival;
	private SeparationBehavior separation;
	private CohesionBehavior cohesion;
	private ObstacleAvoidanceBehavior avoidance;
	private OffsetPursuitBehavior offsetPursuit;
	
	public Steering(final Vehicle owner, Collection<? extends Vehicle> neighbors) {		
		seek = new SeekBehavior();
		seek.setSeeker(owner);
		seek.setWeight(1.f);

		arrival = new ArrivalBehavior();
		arrival.setSeeker(owner);
		arrival.setSlowingDistance(16f);
		arrival.setWeight(1.f);

		separation = new SeparationBehavior(owner);
		separation.setNeighbors(neighbors);
		separation.setWeight(1.f);
		
		cohesion = new CohesionBehavior(owner);
		cohesion.setNeighbors(neighbors);
		cohesion.setWeight(.5f);

		avoidance = new ObstacleAvoidanceBehavior(owner);
		avoidance.setObstacles(neighbors);
		avoidance.setWeight(3.f);
		
		offsetPursuit = new OffsetPursuitBehavior(owner);
		offsetPursuit.setWeight(1.f);
		
		prioritization = new PriorityCombinationBehavior(owner);
		prioritization.addBehavior(avoidance);
		prioritization.addBehavior(separation);
		prioritization.addBehavior(cohesion);
		prioritization.addBehavior(offsetPursuit);
		prioritization.addBehavior(seek);
		prioritization.addBehavior(arrival);
	}
	
	public SeekBehavior getSeek() {
		return seek;
	}

	public ArrivalBehavior getArrivel() {
		return arrival;
	}

	public ArrivalBehavior getArrival() {
		return arrival;
	}

	public SeparationBehavior getSeparation() {
		return separation;
	}

	public CohesionBehavior getCohesion() {
		return cohesion;
	}

	public ObstacleAvoidanceBehavior getAvoidance() {
		return avoidance;
	}

	public Vector2D calculate() {
		Vector2D force = prioritization.calculate();
		return steeringForce.set(force);
	}

	public OffsetPursuitBehavior getOffsetPursuit() {
		return offsetPursuit;
	}

	public Vector2D getSteeringForce() {
		return steeringForce;
	}

}